package com.muqi.app.qlearn.student.org;

import java.util.List;

import com.bumptech.glide.Glide;
import com.easemob.easeui.widget.CircularImage;
import com.muqi.app.qlearn.modles.CreditBean;
import com.muqi.app.qlearn.student.R;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class CreditAdapter extends BaseAdapter {
	private Context context;
	private List<CreditBean> listData;

	public CreditAdapter(Context context, List<CreditBean> listData) {
		this.context = context;
		this.listData = listData;
	}

	@Override
	public int getCount() {
		return listData == null ? 0 : listData.size();
	}

	@Override
	public CreditBean getItem(int position) {
		return listData.get(position);
	}
   
	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams") @Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		final CreditBean itemInfo = listData.get(position);
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_credit_view, null);
			holder.itemAvatar = (CircularImage) convertView.findViewById(R.id.user_circularImage);
			holder.itemName = (TextView) convertView.findViewById(R.id.user_name);
			holder.itemContent = (TextView) convertView.findViewById(R.id.content);
			holder.itemDesc = (TextView) convertView.findViewById(R.id.credit_desc);
			holder.itemScore = (RatingBar) convertView.findViewById(R.id.rating_bar);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		Glide.with(context).load(itemInfo.headpic).dontAnimate()
			.placeholder(R.drawable.ease_default_avatar).into(holder.itemAvatar);
		holder.itemName.setText(itemInfo.username);
		holder.itemContent.setText(itemInfo.content);
		holder.itemDesc.setText(itemInfo.createtime+"    "+itemInfo.subject_or_order_name);
		holder.itemScore.setNumStars(itemInfo.total_comment);
		return convertView;
	}
	
	private class ViewHolder {
		CircularImage itemAvatar;
		TextView itemName;
		TextView itemContent;
		TextView itemDesc;
		RatingBar itemScore;
	}
}
